home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
PC Graphics Unleashed
/
PC Graphics Unleashed.iso
/
ch10
/
raw2poly.c
< prev
next >
Wrap
C/C++ Source or Header
|
1994-05-16
|
1KB
|
64 lines
///////////////////////////////////////////
//
// RAW TO POLYRAY CONVERTER RAW2POLY.C
//
//////////////////////////////////////////
#include <stdio.h>
#include <stdlib.h>
void main(int argc, char *argv[]) {
FILE *infile, *outfile;
float x1, y1, z1,
x2, y2, z2,
x3, y3, z3;
int count = 0;
if(argc < 2) {
printf("Usage: RAW2POLY inputfile outputfile\n");
exit(1);
}
if ((infile = fopen(argv[1], "rt")) == NULL) {
printf("Can't open %s!\n",argv[1]);
exit(1);
}
if ((outfile = fopen(argv[2], "wt")) == NULL) {
printf("Can't open %s!\n",argv[2]);
exit(1);
}
fprintf(outfile," object{\n");
while (!feof(infile)) {
if ((fscanf(infile,"%f",&x1) > 0) &&
(fscanf(infile,"%f",&y1) > 0) &&
(fscanf(infile,"%f",&z1) > 0) &&
(fscanf(infile,"%f",&x2) > 0) &&
(fscanf(infile,"%f",&y2) > 0) &&
(fscanf(infile,"%f",&z2) > 0) &&
(fscanf(infile,"%f",&x3) > 0) &&
(fscanf(infile,"%f",&y3) > 0) &&
(fscanf(infile,"%f",&z3) > 0)) {
if(count)
fprintf(outfile, " + object {");
else
fprintf(outfile, " object {");
fprintf(outfile, " polygon 3, ");
fprintf(outfile, "<%g, %g, %g>,",x1,y1,z1);
fprintf(outfile, "<%g, %g, %g>,",x2,y2,z2);
fprintf(outfile, "<%g, %g, %g>}\n" ,x3,y3,z3);
count++;
}
}
fprintf(outfile," shiny_red\n }\n");
fclose(infile);
fclose(outfile);
}